/**
 * 
 */
var HomePageController=function($scope,$http,$location, PaginatorRR,localStorageService,$log){
	
	$scope.baseUrl = zimgeUrl;
	$scope.formatImage = "?p=0";
	$scope.pageSize = 4;
	$scope.amount = 1;
	
	// add 1
	$scope.addProduct = function(product) {
		product.buyAmount+=1;
	}
	// minus 1
	$scope.minusProduct = function(product) {
		if (product.buyAmount == 1) {
			sweetAlert("亲，不能再减了哦");
			return;
		}
		product.buyAmount =product.buyAmount - 1;
	}
	
	var fetchFunction = function(currentPage, limit, propId, callback) {

		$http.get("../../product/listMProduct", {
			params : {
				'pageSize' : limit,
				'cpage' : currentPage
			}
		}).success(callback);
	}
	
	$scope.products=PaginatorRR(fetchFunction, $scope.pageSize, false);
	
	$log.info($scope.products);
	
	$scope.showLogin = function() {
		$('#my-prompt').modal();
	}
	
	/** login cancel */
	$scope.cancel = function() {
		$('#my-prompt').modal("close");
	}
	$scope.login = function(phone, pwd) {
		var user = {
			'phone' : phone,
			'password' : pwd
		};

		$http({
			method : "post",
			url : '../../adminlogin',
			data : $.param(user), // pass in data
			headers : {
				'Content-Type' : 'application/x-www-form-urlencoded'
			}

		}).success(function(response) {
			//$log.info(response);
			if (response.code == 1) {
				$('#my-prompt').modal("close");
				sweetAlert("登录成功");
			} else if (response.code == 0) {
				sweetAlert("登录失败");
			}

		}).error();
	}
	
	// 进入购物车
	$scope.shoppingCart = function() {

		$location.path("shopCart");
	}
	
	$scope.additem = function(product) {
		$log.info(product);
		// 存
		localStorageService.set(product.id, {
			"product" : product,
			"amount"  : product.buyAmount
		});
		
		sweetAlert("已添加到购物车！");

	}
	
} 